import { _decorator, Component, Label, Node } from 'cc';
import { AudioManager } from '../../../../common/src/manager/AudioManager';
import { PROP_TYPE } from '../../../../common/src/util/Enums';
import { UIManager } from '../../../../framework/ui/uimanager/UIManager';
import DataMgr from '../../../../common/src/util/DataMgr';
const { ccclass, property } = _decorator;

@ccclass('PropertyPanel')
export class PropertyPanel extends Component {
    @property({ type: Node, tooltip:"洗牌"})
    washNode: Node = null
    
    @property({ type: Node, tooltip:"移除"})
    cleanNode: Node = null
    
    @property({ type: Node, tooltip:"凑齐"})
    magnetNode: Node = null
    
    @property({ type: Node, tooltip:"加时"})
    addNode: Node = null
    
    start() {
        this.updatePropertyInfo()
    }

    // =======================================
    // ------------ 内部方法
    // =======================================
    private updatePropertyInfo() {
        this.washNode.getChildByName("countbg").active = DataMgr.washCount > 0
        this.washNode.getChildByName("countbg").getChildByName("Label").getComponent(Label).string = DataMgr.washCount + ""
        
        this.cleanNode.getChildByName("countbg").active = DataMgr.removeCount > 0
        this.cleanNode.getChildByName("countbg").getChildByName("Label").getComponent(Label).string = DataMgr.removeCount + ""
        
        this.magnetNode.getChildByName("countbg").active = DataMgr.magnetCount > 0
        this.magnetNode.getChildByName("countbg").getChildByName("Label").getComponent(Label).string = DataMgr.magnetCount + ""
        
        this.addNode.getChildByName("countbg").active = DataMgr.addCount > 0
        this.addNode.getChildByName("countbg").getChildByName("Label").getComponent(Label).string = DataMgr.addCount + ""
    }

    // =======================================
    // ------------ 事件
    // =======================================
    // ----------------- 点击事件 ----------------- //
    private onPropertyClicked(event, customEventData) {
        AudioManager.playButton()
        
        var type = PROP_TYPE.WASH
        switch(parseInt(customEventData)) {
            case 0:
                type = PROP_TYPE.WASH
                break
            case 1:
                type = PROP_TYPE.CLEAN
                break
            case 2:
                type = PROP_TYPE.MAGNET
                break
            case 3:
                type = PROP_TYPE.ADD
                break
        }
        
        UIManager.open("property:res/prefab/PropertyDialog", (err, res:Node)=>{
            res.getComponent("PropertyDialog").setData({
                type: type
            })
        })
    }

}


